import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
  {
    path:"/",
    name:"Home",
    component:Home
  },
  {
    path:"/login",
    name:"Login",
    component:()=>import("../views/Login.vue")
  },
  {
    path:"/register",
    name:"Register",
    component:()=>import("../views/Register.vue")
  },
  {
    path:"/shopmall",
    name:"Shopmall",
    component:()=>import("../views/Shop_mall.vue")
  },
  {
    path:"/serve",
    name:"Serve",
    component:()=>import("../views/Series/Serve.vue")
  },
  {
    path:"/particulars/:id",
    name:"Particulars",
    component:()=>import("../views/particulars.vue"),
    beforeEnter:(to,from,next)=>{
      window.scroll(0,0);
      next();
    }
  },
  
  {
    path:"/personal",
    name: "Personal",
    component: () => import("../views/PersonalCenter/Personal.vue"),
    beforeEnter: (to, from, next) => {

      // console.log("to", to, "from", from);
      
      next();
    },
    children: [{
      path:"info",
      name: "PersonalInfo",
      component: () => import("../views/PersonalCenter/personalInfo.vue"),
    },{
      path:"shopCar",
      name: "ShopCar",
      component: () => import("../views/PersonalCenter/shopCar.vue"),
    },{
      path:"realOrder",
      name: "RealOrder",
      component: () => import("../views/PersonalCenter/realOrder.vue"),
    },
    {
      path:"shoppingAddress",
      name:"ShoppingAddress",
      component:()=>import("../views/PersonalCenter/shoppingAddress.vue")
      },
      {
        path:"bhistory",
        name:"Bhistory",
        component:()=>import("../views/PersonalCenter/Bhistory.vue")
      }
    ],
  },{
    path:"/order",
    name:"Order",
    component:()=>import("../views/order.vue")
  },

  {
    path:"/payInfo",
    name:"PayInfo",
    component:()=>import("../views/payInfo.vue")
  },
  {
    path:"*",
    name:"error",
    component:()=>import("../views/error.vue")
  },
  {
    path:"/test",
    name:"Test",
    component:()=>import("../views/test.vue")
  },
  {
    path:"/allgoods",
    name:"Allgoods",
    component:()=>import("../views/Allgoods.vue")
  },

]

const router = new VueRouter({
  routes,
  scrollBehavior (to, from, savedPosition) {
    return { x: 0, y: 0 }
  }
})



export default router
